<!--  -->
<template>
  <div class=''>
    <el-dialog
      :title="title"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item
          label="类型"
          prop="rushFeeType"
        >
          <el-select
            v-model="ruleForm.rushFeeType"
            placeholder="请选择活动区域"
          >
            <el-option
              v-for="(item,index) in options"
              :key="index"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="公司名称"
          prop="companyName"
        >
          <el-input
            v-model="ruleForm.companyName"
            placeholder="请填写公司名称"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="开户行"
          prop="openingBank"
        >
          <el-input
            v-model="ruleForm.openingBank"
            placeholder="请填写开户行"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="账号"
          prop="accountNumber"
        >
          <el-input
            @input.native="ruleForm.accountNumber = test(ruleForm.accountNumber)"
            v-model="ruleForm.accountNumber"
            placeholder="请填写账号"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="备注"
          prop="remark"
        >
          <el-input
            type="textarea"
            v-model="ruleForm.remark"
            placeholder="请填写备注"
          ></el-input>
        </el-form-item>
      </el-form>
      <span
        slot="footer"
        class="dialog-footer"
      >
        <el-button
          @click="dialogVisible = false"
          icon="el-icon-circle-close"
        >取 消</el-button>
        <el-button
          icon="el-icon-circle-check"
          type="primary"
          @click="doSubmit"
        >确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// 例如：import 《组件名称》 from '《组件路径》';
import { getDicType } from '@/api/common'
import { addObj, putObj } from '@/api/sysrushfeelist'
export default {
  // import引入的组件需要注入到对象中才能使用
  components: {},
  data () {
    // 这里存放数据
    return {
      dialogVisible: false,
      rules: {
        rushFeeType: [{ required: true, message: '请选择缴费类型', trigger: 'change' }],
        companyName: [{ required: true, message: '请输入公司名称', trigger: 'blur' }],
        remark: [{ required: true, message: '请输入备注信息', trigger: 'blur' }],
        accountNumber: [{ required: true, message: '请输入账号', trigger: 'blur' }],
        openingBank: [{ required: true, message: '请输入开户行', trigger: 'blur' }]
      },
      ruleForm: {
        rushFeeType: '',
        companyName: '',
        remark: '',
        accountNumber: '',
        openingBank: ''
      },
      options: [],
      method: '',
      title: ''
    }
  },
  filters: {
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 方法集合
  methods: {
    test (value) {
      value = value.replace(/[^\d]/g, '')
      return value
    },
    handleClose () {
      this.dialogVisible = false
    },
    init (method, item) {
      this.ruleForm = this.$options.data().ruleForm
      this.method = method
      if (method == 'edit') {
        this.title = '修改信息'
        this.ruleForm = item
        this.ruleForm.rushFeeType = this.ruleForm.rushFeeType + ''
      } else {
        this.title = '添加信息'
      }
      getDicType('sys_pay_type').then(res => {
        this.options = res.data.data
      })
      this.dialogVisible = true
    },
    submint () {

    },
    doSubmit () {
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          // 请求发送
          if (this.method == 'add') {
            addObj(this.ruleForm).then(res => {
              this.dialogVisible = false
              this.$message.success('添加成功')
              this.$emit("refreshList")
            })
          } else {
            putObj(this.ruleForm).then(res => {
              this.dialogVisible = false
              this.$message.success('修改成功')
              this.$emit("refreshList")
            })
          }
        } else {
          return false
        }
      })
    }
  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  created () {

  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted () {
  },
  beforeCreate () { }, // 生命周期 - 创建之前
  beforeMount () { }, // 生命周期 - 挂载之前
  beforeUpdate () { }, // 生命周期 - 更新之前
  updated () { }, // 生命周期 - 更新之后
  beforeDestroy () { }, // 生命周期 - 销毁之前
  destroyed () { }, // 生命周期 - 销毁完成
  activated () { } // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>
<style lang='scss' scoped>
//@import url(); 引入公共css类
</style>